package main

import (
	"fmt"
	"math/rand"
	"time"
)

func main() {
	// var chick [7]float64
	// chick[0] = 3.5
	// chick[1] = 5.2
	// chick[2] = 6.5
	// chick[3] = 7.5
	// chick[4] = 8.1
	// chick[5] = 8.4
	// chick[6] = 6.8
	// totalWeight := 0.0
	// for i := 0; i < len(chick); i++ {
	// 	totalWeight += chick[i]
	// }
	// avgWeight := fmt.Sprintf("%.2f", totalWeight/float64(len(chick)))
	// fmt.Printf("总重量为%.2f\n平均重量为%v\n", totalWeight, avgWeight)

	// var intArr [3]int
	// fmt.Println(intArr)
	// fmt.Printf("intArr地址=%p,intArr[0]地址=%p,intArr[1]地址=%p,intArr[2]地址=%p\n",&intArr,&intArr[0],&intArr[1],&intArr[2])
	// intArr[0] = 10
	// intArr[1] = 20
	// intArr[2] = 30
	// fmt.Printf("intArr地址=%p,intArr[0]地址=%p,intArr[1]地址=%p,intArr[2]地址=%p\n",&intArr,&intArr[0],&intArr[1],&intArr[2])

	// var score [5]float64
	// for i := 0; i < len(score); i++ {
	// 	fmt.Printf("请输入第%d个元素\n", i+1)
	// 	fmt.Scanln(&score[i])
	// }
	// for i := 0; i < len(score); i++ {
	// 	fmt.Printf("第%d个元素=%v", i+1, score[i])
	// }

	//四种初始化数组的方式
	// var numArr01 [3]int = [3]int{1, 2, 3}
	// fmt.Println("numArr01=", numArr01)

	// var numArr02 = [3]int{1, 2, 3}
	// fmt.Println("numArr02=",numArr02)

	// var numArr03 = [...]int{1, 2, 3}
	// fmt.Println("numArr03=", numArr03)

	//index : value
	// var numArr04 = [...]int{1: 600, 2: 500, 3: 500, 0: 400}
	// fmt.Println("numArr04=", numArr04)

	//index : value
	//change value's type
	// numArr05 := [...]string{1: "第二个元素下标是1", 0: "这是第一个元素", 2: "这是第三个元素下标是2哦"}
	// fmt.Println("numArr05=", numArr05)

	//iterate array
	//init
	// heroes := [...]string{"宋江", "吴用", "卢俊义"}
	// for i := 0; i < len(heroes); i++ {
	// 	fmt.Printf("好汉%v=heroes[%d]\n", heroes[i], i)
	// }
	// fmt.Println()
	//The above array capacity has been defined,so the assignment of the following elements will report an error
	//the error info ==> invalid argument: array index 3 out of bounds [0:3] (exit status 2)
	// heroes[3] = "晁盖"\

	//use for-range ways for iterate
	// fruits := [...]string{"orange", "grape", "blueberry"}
	// for index, value := range fruits {
	// 	fmt.Printf("index=%v,value=%v\n", index, value)
	// 	fmt.Printf("fruits[%d]======%v\n", index, fruits[index])
	// }
	//you can use "_" to ignore the return value for example
	// for _, v := range fruits {
	// 	fmt.Println("the value is",v)
	// }

	//default values for element of arrays of differen data types
	// var intArr [3]int
	// var stringArr [3]string
	// var booleanArr [3]bool
	// fmt.Println(intArr)
	// fmt.Println(stringArr)
	// fmt.Println(booleanArr)
	//i can also use fmt.printf() to output my expect result in one line
	// fmt.Printf("intArr=%v, stringArr=%v, booleanArr=%v", intArr, stringArr, booleanArr)

	//array's values transfer
	// var intArr1 [3]int
	// fmt.Println("before tranfered array =", intArr1)// 	before tranfered array = [0 0 0]
	// testTransferArr(intArr1)
	// fmt.Println("after tranfered array =", intArr1)// after tranfered array = [0 0 0]

	//if you want to change values of the array's elements, you can change the values pointed to by the elements' pointers
	// intArrForChange := [3]int{11, 22, 33}
	// changeArrValue(&intArrForChange)
	// fmt.Println("main's array =", intArrForChange)

	//test put 26 english letters in an array and output this array on console
	// var englishLetters [26]byte
	// for i := 0; i < 26; i++ {
	// 	englishLetters[i] = 'A' + byte(i)
	// }
	// for i := 0; i < 26; i++ {
	// 	fmt.Printf("%c", englishLetters[i])
	// }

	//test find the max value in an array
	// testIntArr := [...]int{-1, 50, 60, 40, 90, 50}
	// maxValue := 0
	// for i := 0; i < len(testIntArr); i++ {
	// 	if testIntArr[i] > maxValue {
	// 		maxValue = testIntArr[i]
	// 	}
	// }
	// fmt.Println("maxValue=", maxValue)

	//get array's sum and avg
	// var testArrForInt [5]int = [...]int{-1, 1, 9, 90, 12}
	// sum := 0
	// for i := 0; i < len(testArrForInt); i++ {
	// 	sum += testArrForInt[i]
	// }
	// for _, v := range testArrForInt {
	// 	sum += v
	// }
	// fmt.Printf("sum=%v,avg=%v\n", sum, float64(sum/len(testArrForInt)))

	//随机生成五个数存入数组，并反转打印
	var intArr001 [5]int
	len := len(intArr001)

	rand.Seed(time.Now().UnixNano())
	for i := 0; i < len; i++ {
		intArr001[i] = rand.Intn(100)
	}
	fmt.Println("before transfered", intArr001)
	for i := 0; i < len/2; i++ {
		temp := intArr001[i]
		intArr001[i] = intArr001[len-1-i]
		intArr001[len-1-i] = temp
	}
	fmt.Println("after transfered", intArr001)

}

// func changeArrValue(arr *[3]int) {
// 	(*arr)[1] = 55
// panic("unimplemented")
// }

//transfer func
// func testTransferArr(intArr1 [3]int) {
// panic("unimplemented")
// intArr1[0] = 8
// fmt.Println("in transfer func array =", intArr1) // in transfer func array = [8 0 0]
// }
